/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package dk.eleit;

import java.awt.Color;
import java.awt.Graphics;

/**
 *
 * @author menderleit
 */
public class LineObject {
    private int numPoints;
    private Vector3[] pos;
    private Vector3[] normal;
    private Vector3 rot;
    
    public LineObject(int numPoints) {
        this.numPoints = numPoints;
        pos = new Vector3[numPoints];
        normal = new Vector3[numPoints];
        rot = new Vector3();
        for(int i=0; i<numPoints; i++) {
            pos[i] = new Vector3();
            normal[i] = new Vector3();
        }
    }
    
    public void setPoint(int PointNum, double x, double y, double z) {
        if(PointNum >= 0 && PointNum < numPoints) {
            pos[PointNum].setVector(x, y, z);
        }
    }
    
    public void setRotation(double x, double y, double z) {
        rot.setVector(x, y, z);
    }
    
    public void drawObject(Graphics g, int ScreenWidth, int ScreenHeight) {
        Vector3 v;
        double FOV = (double)ScreenWidth / (double)ScreenHeight;
        int SW2 = ScreenWidth / 2;
        int SH2 = ScreenHeight / 2;
        double px, py;
        double px2, py2;
        int sx, sy;
        int sx2, sy2;
        g.setColor(Color.white);
        for(int i=0; i<this.numPoints; i++) {
            v = pos[i].rotate(rot.getX(), rot.getY(), rot.getZ());
            double z2 = v.getZ() * 0.75 + 150.0;
            double z = v.getZ() + 150.0;
            px = v.getX() / z;
            py = v.getY() / (z / FOV);
            px2 = v.getX() * 0.75 / z2;
            py2 = v.getY() * 0.75 / (z2 / FOV);
            sx = (int)(px * SW2 + SW2);
            sy = (int)(-py * SH2 + SH2);
            sx2 = (int)(px2 * SW2 + SW2);
            sy2 = (int)(-py2 * SH2 + SH2);
            g.drawLine(sx, sy, sx2, sy2);
        }
    }
}
